home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks96 / BootingGallery.sit / Booting Gallery / Booting Gallery (source) / Sources / Duck Game Sources / GunSprite.cpp < prev    next >
Text File  |  1996-06-22  |  2KB  |  146 lines

  1. /***
  2.  *     Created by Bill Hubauer on Fri, Jun 21, 1996 @ 2:53 AM.
  3.  *
  4.  ***/
  5.  
  6.  
  7. #ifndef __GunSprite_H__
  8. #include "GunSprite.h"
  9. #endif
  10.  
  11.  
  12.  
  13.  
  14.  
  15. void    CGunSprite::UpdatePosition() //Override
  16. {
  17.     if(SpaceDownQ()){
  18.         FireGun();
  19.     }else{
  20.         
  21.         short            newPos = GetLocation()->left;
  22.         const Rect&        bounds = *GetGameBounds();
  23.         
  24.         if(LeftArrowQ()){
  25.             newPos -= kMoveInterval;
  26.         }else if(RightArrowQ()){
  27.             newPos += kMoveInterval;
  28.         }
  29.         
  30.         if(newPos < bounds.left){
  31.             newPos = bounds.left;
  32.         }else if(newPos > (bounds.right - Width())){
  33.             newPos = bounds.right - Width();
  34.         }
  35.         
  36.         MoveBy(newPos - GetLocation()->left,0);
  37.     }
  38. }
  39.  
  40.  
  41. static short CalcGunTop(CSpriteWorld* world)
  42. {
  43.     const Rect&        bounds = *(world->GetSpriteCanvas()->GetBounds());
  44.     
  45.     return bounds.bottom - 32;
  46. }
  47.  
  48. inline short    RectWidth(const Rect& r)
  49. {
  50.     return r.right - r.left;
  51. }
  52.  
  53. static short CalcGunLeft(CSpriteWorld* world)
  54. {
  55.     const Rect&        bounds = *(world->GetSpriteCanvas()->GetBounds());
  56.  
  57.     return ((bounds.left + (RectWidth(bounds) / 2)) - 16);
  58. }
  59.  
  60. CGunSprite::CGunSprite(CSpriteWorld* world,CSpriteGame* game)
  61.     :    CGameSprite(world, game, 0,game->GetImage(kBaseImageID), CalcGunTop(world),
  62.              CalcGunLeft(world), game->GetImageMask(kBaseImageID))
  63. {
  64.  
  65. }
  66.  
  67.  
  68. CGunSprite::~CGunSprite()//Override
  69.  
  70. {
  71.  
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. Boolean    CGunSprite::LeftArrowQ()
  81. {
  82.     return KeyIsDownQ(0x7B);
  83. }
  84.  
  85.  
  86. Boolean    CGunSprite::RightArrowQ()
  87. {
  88.     return KeyIsDownQ(0x7C);
  89. }
  90.  
  91. Boolean    CGunSprite::SpaceDownQ()
  92. {
  93.     return KeyIsDownQ(0x31);
  94. }
  95.  
  96.  
  97. void    CGunSprite::FireGun()
  98. {
  99.     short        deltaV,deltaH;
  100.     
  101.     deltaV = -75;
  102.     deltaH = 0;
  103.  
  104.     
  105.     new CBulletSprite(GetWorld(), GetGame(), GetLocation()->top, GetLocation()->left, 
  106.         deltaV, deltaH);
  107.         
  108.     PlaySound(kGunSoundID);
  109.     
  110. }
  111.  
  112.  
  113.  
  114.  
  115. CBulletSprite::CBulletSprite(CSpriteWorld* world,CSpriteGame* game,short startTop,short startLeft,
  116.         short deltaV,short deltaH)
  117.     :    CGameSprite(world, game, 0, game->GetImage(kBulletImageID), startTop, startLeft, 
  118.             game->GetImageMask(kBulletImageID)),
  119.         fDeltaV(deltaV),
  120.         fDeltaH(deltaH)
  121. {
  122.     
  123. }
  124.  
  125.  
  126. CBulletSprite::~CBulletSprite()//Override
  127.  
  128. {
  129.  
  130. }
  131.  
  132.  
  133. void    CBulletSprite::UpdatePosition()//Override
  134. {
  135.     MoveBy(fDeltaH,fDeltaV);
  136.     if(OutOfBoundsQ()){
  137.         delete this;
  138.     }
  139. }
  140.  
  141. void    CBulletSprite::WasHitBy(CSprite* s)//Override
  142. {
  143.  
  144. }
  145.  
  146.